﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using TheDarkKnight;
using UnityEditor;
using UnityEngine;
using static TheDarkKnight.TempletObjectBase;

public class ZoomTemplet : MonoBehaviour
{


    public List<TempletObjectBase> TempletList;

    [Header("放大缩小倍数")]
    [Range(0,100)]
    public float ZoomScale = 1;

    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("开始缩放模型大小");
        string directoryPath = @"Assets/ScriptableObject/x" + ZoomScale + "/";
        string fullDirPath = System.Environment.CurrentDirectory + "/" + directoryPath;
        for (int i = 0; i < TempletList.Count;i++) {
            TempletObjectBase templet = TempletList[i];
            TempletObjectBase data = (TempletObjectBase)ScriptableObject.CreateInstance(templet.TypeName);
            //data.Vectices = templet.Vectices;
            data.TypeName = templet.TypeName;
            data.ModelName = templet.ModelName;
            data.Triangles = templet.Triangles;
            data.SurfaceMaterial = templet.SurfaceMaterial;
            data.SectionMaterial = templet.SectionMaterial;
            data.Vectices = new List<VerticesData>();
            for (int j = 0; j < templet.Vectices.Count; j++) {
                VerticesData newVerticeData = new VerticesData();
                newVerticeData.Vertices = (templet.Vectices[j].Vertices)* ZoomScale;
                newVerticeData.UV = templet.Vectices[j].UV;
                newVerticeData.Normal = templet.Vectices[j].Normal;
                data.Vectices.Add(newVerticeData);
            }
            if (!Directory.Exists(fullDirPath)) {
                Directory.CreateDirectory(fullDirPath);
            }
            AssetDatabase.CreateAsset(data, directoryPath + data.TypeName+"_x"+ ZoomScale + ".asset");
            AssetDatabase.SaveAssets(); //存储资源
            AssetDatabase.Refresh(); //刷新
            Debug.Log("开始缩放模型大小完毕");
        }
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
